/*
 * TazioMessage.java    0.0.2    16/nov/2009
 * 
 * Copyright (c) 2009 mentalsmash.org
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * The use of the Apache License does not indicate that this project is
 * affiliated with the Apache Software Foundation.
 */ 
package org.mentalsmash.tazio.core.messages;

import java.io.Serializable;
import java.net.InetAddress;

import org.mentalsmash.tazio.core.identifiers.OID;
import org.mentalsmash.tazio.core.identifiers.TazioID;
import org.mentalsmash.tazio.core.identifiers.TazioNodeID;
import org.mentalsmash.tazio.core.identifiers.UUIDIdentifiersFactoryImpl;

/**
 * 
 * TazioMessage is the base abstract class from which all messages used in the Tazio 
 * Service will inherit. This is used in order to achieve a common message structure 
 * and to provide a type-of-message-independent way of building and delivering them 
 * across the network.
 * In this class is held a final id value, held by a 
 * {@link OID} object, that will 
 * uniquely identify the message throughout the whole life of the object. 
 * This identifier is passed to subclasses of TazioMessage.
 * 
 * @version 0.0.2	16/nov/2009
 * @author Enrico Savioli <savioli.enrico@gmail.com>
 * @author Andrea Sorbini <as@mentalsmash.org>
 *
 */

public abstract class TazioMessage implements Serializable{

    /**
	 * 
	 */
	private static final long serialVersionUID = 8795281051028743119L;

	protected final TazioID id;
	
	protected TazioID answerTo = null;
    
    public TazioID getID() {
    	
    	return id;
    	
    }
    
    public TazioNodeID getNodeID(){
    	
    	return id.getNode();
    	
    }
    
    public TazioMessage(){

    	UUIDIdentifiersFactoryImpl factory = new UUIDIdentifiersFactoryImpl();
    	id = factory.newID();
    	
    }
    
    public InetAddress getSenderAddress(){
    	
    	return id.getNode().getAddress();
    	
    }
    
    public void setAnswerTo(TazioID id){
    	
    	this.answerTo = id;
    	
    }
    
    public TazioID getAnswerTo(){
    	
    	return this.answerTo;
    	
    }
       
}

